<?php

namespace Cpadmin\Model;

use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Sql; //join
use Cpadmin\Model\User;
use Zend\Db\Sql\Select;

class UserTable extends AbstractTableGateway {

    protected $table = "tbladmin";
    public $sql;

    public function __construct(Adapter $adapter) {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
        $this->resultSetPrototype->setArrayObjectPrototype(new User());
        $this->initialize();
        $this->sql = new Sql($this->adapter);
    }

    public function checklogin($username, $password) {
        $select = $this->sql->select();
        $select->from($this->table);
        $select->where(array('adminusername'=>$username,'adminpassword'=>$password));
       
        $stament = $this->sql->prepareStatementForSqlObject($select);
        $results = $stament->execute();
        
        $array = array();
        foreach ($results as $result) {
            $tmp = array();
            $tmp = $result;
            $array[] = $tmp;
        }
        
        return $array;
        //return $result;
    }

}
